home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
machserver
/
1.098
/
libc
/
strncpy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-03-22
|
2KB
|
61 lines
/*
* strncpy.c --
*
* Source code for the "strncpy" library routine.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/string/RCS/strncpy.c,v 1.2 89/03/22 16:07:14 rab Exp $ SPRITE (Berkeley)";
#endif /* not lint */
#include <string.h>
/*
*----------------------------------------------------------------------
*
* strncpy --
*
* Copy exactly numChars characters from src to dst. If src doesn't
* contain exactly numChars characters, then the last characters are
* ignored (if src is too long) or filled with zeros (if src
* is too short). If src is too long then dst will not be
* null-terminated.
*
* Results:
* The return value is a pointer to the destination string, dst.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *
strncpy(dst, src, numChars)
register char *src; /* Place from which to copy. */
char *dst; /* Place to store copy. */
int numChars; /* Maximum number of characters to copy. */
{
register char *copy = dst;
while (--numChars >= 0) {
if ((*copy++ = *src++) == '\0') {
while (--numChars >= 0) {
*copy++ = '\0';
}
return dst;
}
}
return dst;
}